package neusoft.yuejian_11.activity;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import java.util.List;

import neusoft.yuejian_11.adapter.MasterVideoAdapter;
import neusoft.yuejian_11.base.BaseActivity;
import neusoft.yuejian_11.bean.MasterVideoBean;
import neusoft.yuejian_11.fragment.SpaceItemDecoration;
import neusoft.yuejian_11.listener.RetrofitListener;
import neusoft.yuejian_11.model.MasterModel;
import neusoft.yuejian_11.R;

public class MasterVideoActivity extends BaseActivity implements RetrofitListener {
    private RecyclerView recyclerView;
    private MasterVideoAdapter adapter;
    private TextView textName;
    private String mastersName;
    private TextView textViewMasterName;
    private int masterId;
    private ImageButton imageButtonBack;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_master_video);
        initView();
        initData();
    }

    private void initData() {
        masterId = getIntent().getIntExtra("pm_id",-1);
        mastersName = getIntent().getStringExtra("pm_name");
        textViewMasterName = (TextView) findViewById(R.id.textView_master_name);
        textViewMasterName.setText(mastersName);
        MasterModel m = new MasterModel();
        m.getMasterVideos(String.valueOf(masterId),this);
    }

    private void initView() {
        recyclerView = (RecyclerView)findViewById(R.id.recyclerView);
        imageButtonBack = (ImageButton) findViewById(R.id.imageButtom_back);
        imageButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    @Override
    public void onSuccess(Object o, int flag) {
        List<MasterVideoBean> m=(List<MasterVideoBean>)o;
        adapter = new MasterVideoAdapter(MasterVideoActivity.this,m);
        LinearLayoutManager layoutManager = new LinearLayoutManager(MasterVideoActivity.this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        recyclerView.addItemDecoration(new SpaceItemDecoration(12));
        recyclerView.setItemAnimator(new DefaultItemAnimator());

    }

    @Override
    public void onFail() {

    }

}
